package site.luojie.transfer.service.impl;

import site.luojie.core.annotation.Autowired;
import site.luojie.core.annotation.Component;
import site.luojie.core.annotation.Transactional;
import site.luojie.transfer.dao.AccountDao;
import site.luojie.transfer.domian.Account;

/**
 * @Description:
 * @Author jie.luo
 * @Create: 2020-05-06 18:25
 **/
@Component
public class AccountTransferService {

    @Autowired
    private AccountDao accountDao;

    @Transactional
    public void accountTransfer(String accountSource, String accountTarget, Integer money) throws Exception {

        Account source = accountDao.selectAccountByNumber(accountSource);
        Account target = accountDao.selectAccountByNumber(accountTarget);

        source.setBalance(source.getBalance() - money);
        target.setBalance(target.getBalance() + money);

        accountDao.updateAccountBalance(source);
        int i = 1/0;
        accountDao.updateAccountBalance(target);
    }
}
